<!DOCTYPE html>
<meta name="viewport" content="width=device-width, user-scalable=no">
<link rel="stylesheet" type="text/css" href="resources/animation.css">
<link rel="stylesheet" type="text/css" href="resources/tablet.css">
<script src="resources/perf_test_helper.js"></script>

<container id="container"></container>

<script>
var N = PerfTestHelper.getN(1000);
var duration = 1000;

function startAnimation() {
  var target = document.createElement('target');
  target.i = 0;
  container.appendChild(target);
  target.addEventListener('webkitAnimationEnd', function(e) {
    e.target.style.webkitAnimationName = ((e.target.i++) % 2 ? '' : 'reverse-') + 'anim';
  });
}

requestAnimationFrame(function(t) {
  var base = t;
  var i = 0;

  function staggeredStart(t) {
    elapsed = t - base;
    for (; i < N * elapsed / duration; i++) {
      startAnimation();
    }
    if (i < N) {
      requestAnimationFrame(staggeredStart);
    } else {
      PerfTestHelper.signalReady();
    }
  }
  requestAnimationFrame(staggeredStart);
});
</script>
